package cn.itsource.feign.fallback;

import cn.itsource.doc.CourseDoc;
import cn.itsource.feign.client.CourseFeignClient;
import cn.itsource.result.JSONResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>描述</p>
 *
 * @author 波波老师(微信 ： javabobo0513)
 * @date 2022/11/15-11:09
 */
@Component
public class CourseFeignClientFallback implements FallbackFactory<CourseFeignClient> {

    @Override
    public CourseFeignClient create(Throwable throwable) {
        return new CourseFeignClient(){
            @Override
            public JSONResult saveCourse2Es(CourseDoc doc) {
                throwable.printStackTrace();
                return JSONResult.error("单个课程信息保存到ES失败，走了兜底");
            }

            @Override
            public JSONResult saveBatchCourse2Es(List<CourseDoc> docList) {
                throwable.printStackTrace();
                return JSONResult.error("多个课程信息保存到ES失败，走了兜底");
            }
        };
    }
}